package com.example.hibernate.t.tree;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="t_org")
@SequenceGenerator(name="seq_org", sequenceName="seq_org")
@org.hibernate.annotations.Entity(
		dynamicInsert=true, dynamicUpdate=true
	)
public class Org {
	
	private Long id;
	private String name;
	private Org parent;
	private Set<Org> child = new HashSet<Org>();
	
	@OneToMany(mappedBy="parent")
	public Set<Org> getChild() {
		return child;
	}
	
	@Id
	@GeneratedValue(generator="seq_org")
	public Long getId() {
		return id;
	}
	public String getName() {
		return name;
	}
	
	@ManyToOne
	@JoinColumn(name="parent_id")
	public Org getParent() {
		return parent;
	}
	public void setChild(Set<Org> child) {
		this.child = child;
	}
	private void setId(Long id) {
		this.id = id;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setParent(Org parent) {
		this.parent = parent;
	}
}
